// ignore_for_file: must_be_immutable

import 'package:aitao_flutter/chat/chat_page.dart';
import 'package:aitao_flutter/chat/chat_record_page.dart';
import 'package:aitao_flutter/chat/intimacy_list_page.dart';
import 'package:aitao_flutter/const/common_const.dart';
import 'package:aitao_flutter/im/im_manager.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../style/color_style.dart';
import '../style/text_style.dart';
import 'controller/message_controller.dart';

class MessagePage extends StatefulWidget {
  MessagePage({super.key, required this.imManager});
  IMManager imManager;
  final MessageController controller = Get.put(MessageController());
  @override
  State<MessagePage> createState() => _MessagePageState();
}

class _MessagePageState extends State<MessagePage>
    with SingleTickerProviderStateMixin {
  late TabController tabController;

  @override
  void initState() {
    super.initState();
    tabController = TabController(length: 3, vsync: this, initialIndex: 0);
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MessageController>(builder: ((controller) {
      return SafeArea(
          child: Scaffold(
        backgroundColor: ColorStyle.whiteColor,
        body: Column(children: [
          Container(
            padding: const EdgeInsets.fromLTRB(14, 0, 14, 0),
            height: 44.h,
            color: ColorStyle.whiteColor,
            child:
                Row(crossAxisAlignment: CrossAxisAlignment.center, children: [
              Expanded(
                  child: Container(
                alignment: Alignment.center,
                color: ColorStyle.whiteColor,
                child: TabBar(
                  isScrollable: true,
                  unselectedLabelStyle: const TextStyle(
                      color: ColorStyle.ashGreyColor, fontSize: 15),
                  labelColor: ColorStyle.normalTextColor,
                  indicatorColor: ColorStyle.themeColor,
                  indicatorSize: TabBarIndicatorSize.label,
                  indicatorPadding: const EdgeInsets.only(left: 8, right: 8),
                  indicatorWeight: 3,
                  labelPadding: const EdgeInsets.only(bottom: 5),
                  labelStyle: Styles.boldText_16,
                  tabs: const [
                    Padding(
                        padding: EdgeInsets.only(left: 8, right: 8),
                        child: Text(MessageStringConst.messageText)),
                    Padding(
                        padding: EdgeInsets.only(left: 8, right: 8),
                        child: Text(MessageStringConst.intimacyFriendText)),
                    Padding(
                        padding: EdgeInsets.only(left: 8, right: 8),
                        child: Text(MessageStringConst.chatRecords)),
                  ],
                  controller: tabController,
                ),
              )),
              GestureDetector(
                child: Icon(
                  Icons.more_horiz_outlined,
                  size: 30.w,
                ),
                onTap: () {
                  //清空所有会话的未读计数
                  // NimCore.instance.messageService.clearAllSessionUnreadCount();
                },
              )
            ]),
          ),
          Expanded(
              child: TabBarView(
            controller: tabController,
            children: [
              ATChatPage(
                imManager: widget.imManager,
              ),
              const IntimacyListPage(),
              const ChatRecordPage(),
            ],
          ))
        ]),
      ));
    }));
  }
}
